﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace SportingGoodsExhibitionSystem
{
    /// <summary>
    /// AdminSelectAppling.xaml 的交互逻辑
    /// </summary>
    public partial class AdminSelectAppling : Page
    {
        string strCon = Properties.Resources.strCON;
        public AdminSelectAppling()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            if (textBox.Text == "")
            {
                getAllInfo();
            }

            else
            {
                try
                {
                    int num = Convert.ToInt32(textBox.Text.ToString());


                    SqlCommand cmd = new SqlCommand("select studentId as '学号',studentNa as '姓名', studentCollege as '学院' , reason as '请假原因',data as '申请时间', time as '申请请假开始日期',timeend as '请假结束日期'  from vacation where studentId=@number and status=@st", con);
                    cmd.Parameters.Add("@number", SqlDbType.Int, 10).Value = num;
                    cmd.Parameters.Add("@st", SqlDbType.Int, 10).Value = 1;
                    SqlDataAdapter read = new SqlDataAdapter(cmd);

                    DataTable dt = new DataTable();
                    read.Fill(dt);

                    dataGrid.ItemsSource = dt.DefaultView;
                }
                catch
                {
                    MessageBox.Show("没有此学生");
                }


            }
            con.Close();


        }
        public void getAllInfo()
        {
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            SqlCommand cmd = new SqlCommand("select studentId as '学号',studentNa as '姓名', studentCollege as '学院' , reason as '请假原因', data as '申请时间', time as '申请请假开始日期',timeend as '请假结束日期' from vacation where status = @st", con);
            cmd.Parameters.Add("@st", SqlDbType.Int, 10).Value = 1;
            SqlDataAdapter read = new SqlDataAdapter(cmd);

            DataTable dt = new DataTable();
            read.Fill(dt);

            DataTable dat = dt;
            dataGrid.ItemsSource = dat.DefaultView;
            con.Close();
        }
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            SqlCommand cmd = new SqlCommand("select studentId as '学号',studentNa as '姓名', studentCollege as '学院' , reason as '请假原因', data as '申请时间', time as '申请请假开始日期',timeend as '请假结束日期' from vacation where status=@st", con);
            cmd.Parameters.Add("@st", SqlDbType.Int, 10).Value = 1;
            SqlDataAdapter read = new SqlDataAdapter(cmd);

            DataTable dt = new DataTable();
            read.Fill(dt);

            DataTable dat = dt;
            dataGrid.ItemsSource = dat.DefaultView;
            con.Close();
        }
    }
}
